package com.own.component.common.login.user;

import com.own.constant.ConstantAccount;
import lombok.Getter;
import org.apache.commons.lang3.StringUtils;

/**
 * DefaultLoginUser
 *
 * @author chenxueli
 * @date 2023-08-10 16:30:35
 */
public class DefaultLoginUser implements BaseLoginUser {

    public static final BaseLoginUser DEFAULT = new DefaultLoginUser();
    private final boolean isLogin;

    @Getter
    private String token;
    @Getter
    private Long userId;
    @Getter
    private String userName;
    @Getter
    private Integer accountType;
    @Getter
    private String client;

    public DefaultLoginUser() {
        this.isLogin = false;
    }

    public DefaultLoginUser(
            String token,
            Long userId,
            String userName,
            int accountType,
            String client
    ) {
        this.token = token;
        this.userId = userId;
        this.userName = userName;
        this.accountType = accountType;
        this.client = client;
        this.isLogin = true;
    }

    public DefaultLoginUser(BaseLoginUser loginUser) {
        this.token = loginUser.token();
        this.userId = loginUser.userId();
        this.userName = loginUser.userName();
        this.isLogin = loginUser.isLogin();
        this.accountType = loginUser.accountType();
    }

    /**
     * 获取登录的token令牌
     *
     * @return token
     */
    @Override
    public String token() {
        return StringUtils.isEmpty(token) ? "-" : token;
    }

    /**
     * 获取登录的用户id
     *
     * @return 用户id
     */
    @Override
    public Long userId() {
        return userId == null ? -1L : userId;
    }

    /**
     * 获取登录的用户名称
     *
     * @return 用户名称
     */
    @Override
    public String userName() {
        return StringUtils.isEmpty(userName) ? "-" : userName;
    }

    /**
     * 获取登录的账号类型
     *
     * @return 账号类型 1=普通账号 2=管理员
     */
    @Override
    public Integer accountType() {
        return this.accountType == null ? ConstantAccount.Type.NORMAL : accountType;
    }

    /**
     * 客户端信息
     *
     * @return 客户端信息
     */
    @Override
    public String client() {
        return client;
    }

    /**
     * 是否登录
     *
     * @return 是否已经登录
     */
    @Override
    public boolean isLogin() {
        return isLogin;
    }
}
